export function mapFun (map, datalist) {
  map.clearMap()

  function createInfoWindow (data) {
    let content = `<div style='width: 23.875rem;background: url(${process.env.BASE_URL}img/04.png) no-repeat;background-size: 100% 100%;padding:2rem'>
        <p class="font_s20 colorF">${data.jgmc}</p>
        <p>
          <img class="verticM" style="height:1.125rem;" src="${process.env.BASE_URL}img/05.png" alt="">&nbsp;&nbsp;
          <span class="Bold font_s16" style="color:#28A1FF">${data.jgdz} </span>
        </p>
        <p>
          <span class="Bold font_s16" style="color:#B0D5ED">法人代表：${data.fddbr}</span>
        </p>
        <p>
          <span class="Bold font_s16" style="color:#B0D5ED">机构代码：${data.jgdm}</span>
        </p>
        <p style='border:1px solid #72F6F8;padding-top:10px;box-sizing:border-box;display:inline-block;width:78px;height:60px;text-align:center;color:#72F6F8;'>
           <span>${data.fxfs}</span><br/>
           <span>风险分</span>
        </p>
        <p style='border:1px solid #72F6F8;padding-top:10px;box-sizing:border-box;width:78px;height:60px;display:inline-block;text-align:center;color:#72F6F8;'>
           <span>${data.fxdj}</span><br/>
           <span>风险等级</span>
        </p>
        ${(data.jgmc === '上海海亿达护理站' || data.jgmc === '上海浦东孝缘社区服务中心') ? `<p style='display:inline-block;'><span style='color:#72F6F8;' 
            id='smLis' onclick="window.vm.opencs('${data.jgmc}')">生命周期</span> </p>` : ''
}        
      </div>`
    var info = document.createElement('div')
    info.className = 'custom-info input-card content-window-card'

    var middle = document.createElement('div')
    middle.className = 'info-middle'
    middle.innerHTML = content
    info.appendChild(middle)
    return info
  }
  // 创建点
  for (const elem of datalist.values()) {
    let arr = []
    arr.push(elem.jg)
    arr.push(elem.wd)
    elem.lnglat = arr
  }
  let infoWindow = new AMap.InfoWindow({ isCustom: true, offset: new AMap.Pixel(0, -30) })
  console.log(datalist)
  for (let i = 0, marker; i < datalist.length; i++) {
    let icon = require('../assets/icon01.png')
    if (datalist[i].fxdj === '中风险') {
      icon = require('../assets/icon02.png')
    } else if (datalist[i].fxdj === '高风险') {
      icon = require('../assets/icon03.png')
    } else if (datalist[i].fxdj === '低风险') {
      icon = require('../assets/icon04.png')
    }
    marker = new AMap.Marker({
      position: datalist[i].lnglat,
      icon: icon,
      map: map
    })
    marker.content = createInfoWindow(datalist[i])
    marker.on('click', markerClick)
    marker.emit('click', { target: marker })
  }

  function markerClick (e) {
    infoWindow.setContent(e.target.content)
    if (e.pixel) { // 初始不打开弹窗
      infoWindow.open(map, e.target.getPosition())
    }
  }

  map.setFitView()
};
